package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.Order;
import cn.wolfcode.trip.base.query.OrderQueryObject;
import cn.wolfcode.trip.base.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

/**
 * 订单资源控制器
 *
 * @author Lyu
 */
@Controller
@RequestMapping("/order")
public class OrderController {

    private final IOrderService orderService;

    @Autowired
    public OrderController(IOrderService orderService) {
        this.orderService = orderService;
    }

    /**
     * 分类查询订单列表
     *
     * @param model x
     * @param qo    x
     * @return x
     */
    @RequestMapping("/list")
    public Object list(Model model, @ModelAttribute("qo") OrderQueryObject qo) {
        qo.setPageSize(8);
        model.addAttribute("pageInfo", orderService.queryForList(qo));
        return "/order/list";
    }

    /**
     * 更新订单总积分
     *
     * @param order 订单对象
     * @return x
     */
    @RequestMapping("/saveOrUpdate")
    public Object saveOrUpdate(Order order) {
        orderService.updateTotalIntegralById(order);
        return "redirect:/order/list.do";
    }
}
